// JavaScript Document
function searchConfirmedList(pageNum){
    var param = {};
    // 申请店铺id
    param.startDate = $("#startDate").val();
    param.endDate = $("#endDate").val();
    $('tr[name="confirmedData"]').remove();
    param.storeId = $("#store").val();
    param.pageNum = pageNum;
    var storeName = $("#store").find("option:selected").text();
    var allAmount = 0;
    var pageResult = doAjax(expensy_applys_list, param);
    if(pageResult.t && pageResult.t.length != 0){
        // 如果有数据，则加载页面信息
        $.each(pageResult.t, function (index, value) {
            allAmount = allAmount + (value.price * value.goodsNumber);
            var last = "<td ></td>";
            if(value.canAdd){
                last = "<td ><a href='javascript:;' onclick='add(this)' expenseApplyId="+value.id+" class=\"sup-btn\">追加</a></td>"
            }
            var tr ="<tr name='confirmedData'>"+
                "<td >"+value.code+"</td>"+
                "<td >"+value.expenseStoreName+"</td>"+
                "<td >"+value.applyUserName+"</td>"+
                "<td >"+value.createTime+"</td>"+
                "<td >"+value.goodsName+"</td>"+
                "<td >"+value.price+"</td>"+
                "<td >"+value.remark+"</td>"+
                last
            "</tr>"
            $('#applyList').append(tr);
        });
    }
    $("#allAmount").text(allAmount);
    $("#storeName").text(storeName);
    $('#box').paging({
        initPageNo: pageResult.pageNum, // 初始页码
        totalPages: pageResult.pageCount, //总页数
        totalCount: '合计' + pageResult.total + '条数据', // 条目总数
        slideSpeed: 600, // 缓动速度。单位毫秒
        jump: false, //是否支持跳转
        callback: function(page) { // 回调函数
            searchConfirmedList(page);
        }
    });
    //return pageResult;
}
// 追加跳转
function add(obj) {
    var expenseApplyId = $(obj).attr("expenseApplyId");
    location.href = add_expense_apply_html + "?expenseApplyId=" + expenseApplyId;
}

function exportExcel(){
    var startDate = $("#startDate").val();
    var endDate = $("#endDate").val();
    var storeId = $("#store").val();
    window.location.href = confirmed_expensy_applys_export + "?startDate="+startDate+"&storeId="+storeId+"&endDate="+endDate;
}
$(function(){
    // 初始化店铺列表
    var stores = doAjaxOnlyUrl(store_list);
    var store = $("#store");
    store.prepend("<option value='0'>全部店铺</option>");
    for(var i = 0; i < stores.length; i ++){
        store.append("<option value="+stores[i].id+">"+stores[i].name+"</option>");
    }
    searchConfirmedList(1);
    laydate.render({
        elem: '#startDate'
    });
    laydate.render({
        elem: '#endDate'
    });

});


























